package com.example.Controller;

import com.example.mapper.UserMapper;
import com.example.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/queryUserList")
    public List<User> queryUserList() {
        List<User> userList = userMapper.queryUserList();
        for (User item : userList) {
            System.out.println(item);
        }
        return userList;
    }

    @RequestMapping("/queryUserById/{id}")
    public String queryUserById(@PathVariable int id){
        User user = userMapper.queryUserById(id);
        System.out.println("查询ID：" + id);
        System.out.println(user);
        return user.toString();
    }

    //增加用户
    @RequestMapping("/addUser")
    public String addUser() {
        userMapper.addUser(new User(50, "阿毛", "123456"));
        return "OK";
    }

    //修改用户
    @RequestMapping("/updateUser")
    public String updateUser() {
        userMapper.updateUser(new User(50, "阿毛", "654321"));
        return "OK";
    }

    //根据id删除用户
    @RequestMapping("/deleteUser")
    public String deleteUser() {
        userMapper.deleteUser(50);
        return "OK";
    }




}
